import {defineStore} from "pinia";
import {reqC1, reqC2, reqC3} from "@/api/product/attr";
import {ref} from "vue";
import type {CategoryResponseData, CategoryObj} from "@/api/product/attr/type.ts";
import type {CategoryState} from "@/stores/modules/types/type.ts";

export const useCategoryStore = defineStore('categoryStore', ():CategoryState => {
    const category1 = ref<Array<CategoryObj>>([])
    const category2 = ref<Array<CategoryObj>>([])
    const category3 = ref<Array<CategoryObj>>([])
    const C1Id = ref<number | string>('')
    const C2Id = ref<number | string>('')
    const C3Id = ref<number | string>('')

    const getC1 = async () => {
        const result:CategoryResponseData = await reqC1()
        if(result.code === 200) {
            category1.value = result.data
            console.log("this is category1", category1.value)
        }
    }

    const getC2 = async () => {
        const result: CategoryResponseData = await reqC2(C1Id.value)
        if(result.code === 200) {
            category2.value = result.data
            console.log("this is category2", category2.value)
        }
    }

    const getC3 = async () => {
        const result:CategoryResponseData = await reqC3(C2Id.value)
        if(result.code === 200) {
            category3.value = result.data
            console.log("this is category3", category3.value)
        }
    }

    return {
        category1,
        category2,
        category3,
        C1Id,
        C2Id,
        C3Id,
        getC1,
        getC2,
        getC3,
    }
})